import logger from "../utils/logger";
import { dbName } from "./constant";

// 创建数据表表
function createTable() {
	return new Promise((resolve) => {
		const creatDates = `
      CREATE TABLE IF NOT EXISTS dates (
        dateId INTEGER PRIMARY KEY AUTOINCREMENT,
        date TEXT NOT NULL
      )`;
		const createClocks = `
      CREATE TABLE IF NOT EXISTS clocks (
        clockId INTEGER PRIMARY KEY AUTOINCREMENT,
        dateId INTEGER NOT NULL,
        time TEXT NOT NULL
      )`;

		plus.sqlite.executeSql({
			name: dbName,
			sql: [creatDates, createClocks],
			success: () => {
				logger('表创建成功');
				resolve(true);
			},
			fail: (e) => {
				logger('创建表失败:', e.message);
				resolve(false);
			}
		});
	});
}

export default createTable;